package com.chaodev.base.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.chaodev.base.dao.GrowthSystemDao;
import com.chaodev.base.model.GrowthSystem;
import com.chaodev.base.model.UserInfo;
import com.chaodev.base.service.GrowthSystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class GrowthSystemServiceImpl implements GrowthSystemService {
    @Autowired
    private GrowthSystemDao growthSystemDao;

    @Override
    public List<GrowthSystem> queryList(GrowthSystem growthSystem) {
        return growthSystemDao.queryList(growthSystem);
    }

    @Override
    public GrowthSystem findDataById(Integer id) {
        return growthSystemDao.findDataById(id);
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public void saveData(GrowthSystem growthSystem, UserInfo userInfo) {
        if(ObjectUtil.isNotNull(growthSystem.getId()) && growthSystem.getId()>0){
            growthSystem.setUpdateUser(userInfo.getUserId());
            growthSystem.setUpdateTime(LocalDateTime.now());
            growthSystemDao.updateDataById(growthSystem);
        }else{
            growthSystem.setCUser(userInfo.getUserId());
            growthSystem.setUpdateUser(userInfo.getUserId());
            growthSystemDao.insertData(growthSystem);
        }
    }

    @Override
    public void deleteDataById(List<Integer> ids) {
        growthSystemDao.deleteDataById(ids);
    }
}
